/**
 * 
 * @author  phoenics@126.com
 * @version v.0.1
 * @date  2018年3月13日 下午2:34:26 
 * 
 */
package phoenics.upservice;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.client.RestTemplate;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 *
 */
@SpringBootApplication
@EnableSwagger2
@EnableCaching
public class Application {
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Application.class);

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

	@Bean
	public Docket createRestApi() {
	     ParameterBuilder tokenPar = new ParameterBuilder();  
        List<Parameter> pars = new ArrayList<Parameter>();  
        tokenPar.name("Authorization").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();  
        pars.add(tokenPar.build());  
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(new ApiInfoBuilder().title("upservice引擎服务 APIs").description("").version("1.0").build())
				.globalOperationParameters(pars)  
				 .pathMapping("/api")
				.select().apis(RequestHandlerSelectors.basePackage("phoenics.upservice.restcontroller"))
				.paths(PathSelectors.any()).build();
	}

/*	@Value("${gocom.api.superapp.appid}")
	String appid = "supu3fg612wtd";
	@Value("${gocom.api.superapp.secret}")
	String secret = "1uj2mte5--";*/
	

/*	@Bean("apiurl")
	public String gocomeApiUrl() {
		return apiUrl;
	}*/


	/*
	 * @Bean public MultiValueMap<String, String> superappConfig() {
	 * MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
	 * requestEntity.add("appid", appid); requestEntity.add("secret", secret);
	 * return requestEntity; }
	 */
	@Bean
	public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
		return new PropertySourcesPlaceholderConfigurer();
	}

	@Bean
	public RestTemplate restTemplate(RestTemplateBuilder builder) {
		return builder.build();
	}
}
